package com.wn.icloud.service.impl;

import com.wn.icloud.dao.BaseDao;
import com.wn.icloud.domain.BaseEntityDomain;
import com.wn.icloud.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * @author liguangcai
 * @date 2018/11/30 16:18
 */
@Transactional
public class BaseServiceImpl<T extends BaseEntityDomain,ID extends Serializable,Dao extends BaseDao<T, ID>>  implements BaseService<T, ID> {

	@Autowired
	protected Dao dao;

	@Override
	public List<T> findAll() {
		return dao.findAll();
	}

	@Override
	public List<T> findAll(Sort sort) {
		return dao.findAll(sort);
	}

	@Override
	public List<T> findAllById(Iterable<ID> ids) {
		return dao.findAllById(ids);
	}

	@Override
	public <S extends T> List<S> saveAll(Iterable<S> entities) {
		return dao.saveAll(entities);
	}

	@Override
	public void flush() {
		dao.flush();
	}

	@Override
	public <S extends T> S saveAndFlush(S entity) {
		return dao.saveAndFlush(entity);
	}

	@Override
	public void deleteInBatch(Iterable<T> entities) {
		dao.deleteInBatch(entities);
	}

	@Override
	public void deleteAllInBatch() {
		dao.deleteAllInBatch();
	}

	@Override
	public T getOne(ID id) {
		return dao.getOne(id);
	}

	@Override
	public <S extends T> List<S> findAll(S entity) {
		return dao.findAll(Example.of(entity));
	}

	@Override
	public <S extends T> Page<S> findAll(S entity, Pageable pageable) {
		return dao.findAll(Example.of(entity),pageable);
	}

	@Override
	public <S extends T> List<S> findAll(Example<S> example, Sort sort) {
		return dao.findAll(example, sort);
	}

	@Override
	public Page<T> findAll(Pageable pageable) {
		return this.dao.findAll(pageable);
	}

	@Override
	public <S extends T> Optional<S> findOne(S entity) {
		return dao.findOne(Example.of(entity));
	}

	@Override
	public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
		return this.dao.findAll(example, pageable);
	}

	@Override
	public <S extends T> long count(Example<S> example) {
		return this.dao.count(example);
	}

	@Override
	public <S extends T> boolean exists(S enitiy) {
		return  this.dao.exists(Example.of(enitiy));
	}

	@Override
	public <S extends T> S save(S entity) {
		return this.dao.save(entity);
	}

	@Override
	public Optional<T> findById(ID id) {
		return this.dao.findById(id);
	}

	@Override
	public boolean existsById(ID id) {
		return this.dao.existsById(id);
	}

	@Override
	public long count() {
		return this.dao.count();
	}

	@Override
	public void deleteById(ID id) {
		this.dao.deleteById(id);
	}

	@Override
	public void delete(T entity) {
		this.dao.delete(entity);
	}

	@Override
	public void deleteAll(Iterable<? extends T> entities) {
		this.dao.deleteAll(entities);
	}

	@Override
	public void deleteAll() {
		this.dao.deleteAll();
	}

	@Override
	public Optional<T> findOne(Specification<T> spec) {
		return this.dao.findOne(spec);
	}

	@Override
	public List<T> findAll(Specification<T> spec) {
		return this.dao.findAll(spec);
	}

	@Override
	public Page<T> findAll(Specification<T> spec, Pageable pageable) {
		return this.dao.findAll(spec, pageable);
	}

	@Override
	public List<T> findAll(Specification<T> spec, Sort sort) {
		return this.dao.findAll(spec, sort);
	}

	@Override
	public long count(Specification<T> spec) {
		return this.dao.count();
	}



}
